package io.jt808.proto.cmd;

import io.norland.buffer.AutoBuffer;
import io.norland.annotations.Proto;
import io.norland.proto.IProto;
import lombok.Data;

/**
 * 终端控制
 */
@Proto("8105")
@Data
public class JT8105 implements IProto {
    /**
     * 命令字
     */
    private byte commandWord;
    /**
     * 命令参数项
     */
    private String commandParameters;

    public byte[] writeToBytes() {
        AutoBuffer buff = new AutoBuffer();
        buff.writeByte(commandWord);
        if (commandParameters != null)
            buff.writeGbkString(commandParameters);
        return buff.array();
    }

    public void readFromBuf(AutoBuffer buff) {
        commandWord = buff.readByte();
        if (buff.isReadable())
            commandParameters = buff.readGbkString();
    }

//    public static void main(String[] args) {
////        String orderParams = "127.0.0.1;8080;中华民族";
////        byte[] bytes1 = Tools.HexString2Bytes(Tools.string2GbkHex(orderParams));
////        byte[] bytes2 = new byte[1 + bytes1.length];
////        bytes2[0] = 0x01;
////        System.arraycopy(bytes1, 0, bytes2, 1, bytes1.length);
//        byte[] bytes=new byte[]{0x03};
//        AutoBuffer buffer = new AutoBuffer(bytes);
//        JT8105 jt8105 = new JT8105();
//        jt8105.readFromBuf(buffer);
//        System.out.println(new String(bytes).equals(new String(jt8105.writeToBytes())));
//    }
}